<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>index</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="__STATIC__/xadmin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/xadmin/css/xadmin.css">
    <script src="__STATIC__/xadmin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__STATIC__/xadmin/js/xadmin.js"></script>
</head>

<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" method="get" action="{:url('tools/coupon');}">
                        <div class="layui-input-inline layui-show-xs-block">
                            <input class="layui-input" placeholder="开始时间" value="{$starttime}" name="starttime" id="start"></div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <input class="layui-input" placeholder="失效时间" value="{$endtime}" name="endtime" id="end"></div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <input type="text" value="{$code}" name="code" placeholder="优惠码"
                                   autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <select name="type">
                                <option value="">类型</option>
                                {volist name="typeList" id="vty" key="key" }
                                    <option value="{$key-1}" {if ($key-1)==$type}selected{/if} >{$vty}</option>
                                {/volist}
                            </select>
                        </div>

                        <div class="layui-input-inline layui-show-xs-block">
                            <select name="range">
                                {volist name="rangeList" id="vrg" key="ke" }
                                    <option value="{$ke-1}" {if ($ke-1)==$range}selected{/if} >{$vrg}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sreach">
                                <i class="layui-icon">&#xe615;</i>
                            </button>
                        </div>
                        <div class="layui-input-inline layui-show-xs-block" style="float: right">
                            <a class="layui-btn" href="javascript:;" onclick="xadmin.open('添加优惠券','{:url('add');}',800,600)"><i class="layui-icon">&#xe654;</i>添加优惠券</a>
                        </div>
                    </form>

                </div>
                <!--<div class="layui-card-header">
                    <button class="layui-btn" onclick="xadmin.open('添加试听','{:url('shiting/add');}',680,450)"><i class="layui-icon"></i>添加</button>
                </div>-->
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th width="30">ID</th>
                            <th>优惠码</th>
                            <th>适用套餐</th>
                            <th>开始时间</th>
                            <th>失效时间</th>
                            <th>类型</th>
                            <th>币种</th>
                            <th>优惠情况</th>
                            <th>添加时间</th>
                            <th>使用情况</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist name="list" id="vo" key="key"}
                        <tr>
                            <td>{$vo.id}</td>
                            <td>{$vo.code}</td>
                            <td>
                                {if $vo['tc_id']}
                                {:idtrans($vo['tc_id'],'kecheng_taocan','title')}
                                {else/}
                                所有套餐
                                {/if}
                            </td>
                            <td>
                                {if $vo['starttime']}
                                {:date('Y-m-d H:i:s',$vo['starttime'])}
                                {else/}
                                    ---
                                {/if}
                            </td>
                            <td>
                                {if $vo['endtime']}
                                {:date('Y-m-d H:i:s',$vo['endtime'])}
                                {else/}
                                永久有效
                                {/if}
                            </td>
                            <td>{$typeList[$vo['type']]}</td>
                            <td>{$rangeList[$vo['range']]}</td>
                            <td>
                                {if $vo['type']==1}
                                抵用券-{$rangeList[$vo['range']]}-{$vo['di']}元
                                {elseif $vo['type']==2 /}
                                折扣券-{$rangeList[$vo['range']]}-{$vo['zhe']}%
                                {elseif $vo['type']==3 /}
                                满减券-{$rangeList[$vo['range']]}-满{$vo['man']}减{$vo['jian']}
                                {else/}
                                暂无信息
                                {/if}
                            </td>
                            <td>{:date('Y-m-d H:i:s',$vo['addtime'])}</td>
                            <td>{$vo['id']|getcoupon}</td>
                            <td>
                                <a href="javascript:;" title="修改优惠券" onclick="xadmin.open('修改优惠券','{:url('add',['id'=>$vo['id']]);}',800,600)">
                                    <i class="layui-icon">&#xe642;</i>
                                </a>
                                <a href="javascript:;" title="发送邮件" onclick="xadmin.open('发送邮件','{:url('emails',['id'=>$vo['id']]);}',600,400)">
                                    <i class="layui-icon">&#xe609;</i>
                                </a>
<!--                                <a href="javascript:;" title="立即失效" onclick="setSx(this)" cid="{$vo.id}">-->
<!--                                    <i class="layui-icon">&#xe64f;</i>-->
<!--                                </a>-->
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        <style>.pagination{display: inline-block;}</style>
                        <p style="padding:10px;display:inline-block;">共&nbsp;&nbsp;{$list->total()}&nbsp;条</p> {$list->render()} 
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['laydate', 'form'],
        function () {
            var laydate = layui.laydate;
            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end' //指定元素
            });
        });
    function setSx(vs){
        console.log($(vs).log());
        var id=$(vs).attr('cid');
        $.ajax({
            url:"{:url('setSx')}",
            data:{table:"coupon",id:cid}
        })
    }
    //删除
    function del(obj, id, name) {
        layer.confirm('确认要删除' + name + '吗？', function (index) {
            $.ajax({
                type: "post",
                url: "{:url('shiting/del');}",
                data: {
                    id: id
                },
                success: function (data) {
                    if (data.status == 1) {
                        layer.msg('删除成功!', {icon: 1, time: 1000});
                        setTimeout(function () {
                            location.href = "{:url('shiting/index');}";
                        }, 1000);
                    } else {
                        layui.use('layer', function () {
                            var layer = layui.layer;
                            layer.msg(data.message, {
                                time: 2000
                            });
                        });
                    }
                }
            });
            return false;
        });
    }
    function doCanel(vd) {
        layer.open({
            content:"确定要取消本次试听课预约吗？",
            title:'确定取消',
            btn:['确定','取消'],
            yes:function(){
                var sid=$(vd).attr('sid');
                $.post("{:url('doChanel')}",{sid:sid},function(res){
                    if(res.code==1){
                        layer.msg('已取消');
                    }else{
                        layer.msg('取消失败');
                    }
                    // window.location.reload();
                })
            },
            btn2: function(index, layero){

            },
            cancel: function(){
            //右上角关闭回调
            //取消操作
            //return false 开启该代码可禁止点击该按钮关闭
        }
        })
    }

</script>

</html>